package com.ee.chat.admin.controller.operatemanage;

import com.ee.chat.admin.service.IRemarkService;
import com.ee.chat.common.bean.Result;
import com.ee.chat.common.entity.UserRemarkLog;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Author AppiJ
 * @Date 2020/10/10 0:43
 */
@RestController
@RequestMapping("operate/remark")
public class RemarkController {
    private Logger log = LoggerFactory.getLogger(this.getClass());

    @Resource
    IRemarkService remarkService;

    /**
     * 获取用户备注列表
     * @Author AppiJ
     * @Date 2020/10/10 0:45
     * @param
     * @return
     */
    @RequestMapping("list")
    public Result list(HttpServletRequest request, Integer userId, String createTime,
                       @RequestParam Integer page, @RequestParam Integer limit){
        try{
            return remarkService.list(request, userId, createTime, page, limit);
        }catch (Exception e){
            log.error("【获取用户备注列表错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 编辑用户备注
     * @Author AppiJ
     * @Date 2020/10/16 22:27
     * @param
     * @return
     */
    @RequestMapping("toEdit")
    public Result toEdit(HttpServletRequest request, @RequestParam(required = false) Integer id){
        try {
            return remarkService.toEdit(request, id);
        } catch(Exception e){
            log.error("【编辑用户备注错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 保存用户备注记录
     * @Author AppiJ
     * @Date 2020/10/11 10:52
     * @param
     * @return
     */
    @RequestMapping("edit")
    public Result edit(HttpServletRequest request, UserRemarkLog remarkLog){
        try{
            return remarkService.edit(request, remarkLog);
        }catch (Exception e){
            log.error("【保存用户备注记录错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 删除用户备注记录
     * @Author AppiJ
     * @Date 2020/10/11 10:59
     * @param
     * @return
     */
    @RequestMapping("del")
    public Result del(HttpServletRequest request, @RequestParam("ids[]") List<Integer> ids){
        try{
            return remarkService.del(request, ids);
        }catch (Exception e){
            log.error("【删除用户备注记录错误】", e);
        }
        return Result.returnFailure();
    }

}
